From: Jonas Dreßler Date: Fri, 26 Feb 2021 15:08:20 +0000 (+0100) Subject: keyboard: Add proper tracking of window movements to focus tracker X-Git-Tag: archive/raspbian/50.5-1+rpi1~1^2~616^2^2~123 X-Git-Url: https://dgit.raspbian.org/%22http://www.example.com/cgi/%22/%22http:/www.example.com/cgi/%22?a=commitdiff_plain;h=95ed7c7a06bd8b79da5e74e3f497ebf970449fee;p=gnome-shell.git keyboard: Add proper tracking of window movements to focus tracker So far the FocusTracker of the OSK can only recognize grab ops on a window, that is when the user grabs the window using a mouse or the touchscreen and actively drags it somewhere. Window can also be moved using keyboard shortcuts, fullscreen buttons or other ways which don't rely on grabs. Start also supporting those window movements by listening to the "position-changed" signal on the currently focused window and emitting the new "window-moved" signal in that case. Because the OSK sometimes moves windows by itself, we temporarily disconnect from that new signal while we move the focused window in _windowSlideAnimationComplete(). This also takes care of resetting this._focusWindowStartY on movements of the window. Part-of: --- diff --git a/js/ui/keyboard.js b/js/ui/keyboard.js index cc922c285..ce4f11fab 100644 --- a/js/ui/keyboard.js +++ b/js/ui/keyboard.js @@ -592,6 +592,11 @@ var FocusTracker = class { } destroy() { + if (this._currentWindow) { + this._currentWindow.disconnect(this._currentWindowPositionChangedId); + delete this._currentWindowPositionChangedId; + } + global.display.disconnect(this._notifyFocusId); global.display.disconnect(this._grabOpBeginId); Main.inputMethod.disconnect(this._cursorLocationChangedId); @@ -605,7 +610,18 @@ var FocusTracker = class { } _setCurrentWindow(window) { + if (this._currentWindow) { + this._currentWindow.disconnect(this._currentWindowPositionChangedId); + delete this._currentWindowPositionChangedId; + } + this._currentWindow = window; + + if (this._currentWindow) { + this._currentWindowPositionChangedId = + this._currentWindow.connect('position-changed', () => + this.emit('window-moved')); + } } _setCurrentRect(rect) { @@ -1275,13 +1291,12 @@ var Keyboard = GObject.registerClass({ this._focusTracker = new FocusTracker(); this._connectSignal(this._focusTracker, 'position-changed', this._onFocusPositionChanged.bind(this)); - this._connectSignal(this._focusTracker, 'window-grabbed', () => { - // Don't use _setFocusWindow() here because that would move the - // window while the user has grabbed it. Instead we simply "let go" - // of the window. - this._focusWindow = null; - this._focusWindowStartY = null; - }); + this._connectSignal(this._focusTracker, 'window-grabbed', + this._onFocusWindowMoving.bind(this)); + + this._windowMovedId = this._focusTracker.connect('window-moved', + this._onFocusWindowMoving.bind(this)); + // Valid only for X11 if (!Meta.is_wayland_compositor()) { this._connectSignal(this._focusTracker, 'focus-changed', (_tracker, focused) => { @@ -1328,6 +1343,11 @@ var Keyboard = GObject.registerClass({ } _onDestroy() { + if (this._windowMovedId) { + this._focusTracker.disconnect(this._windowMovedId); + delete this._windowMovedId; + } + if (this._focusTracker) { this._focusTracker.destroy(); delete this._focusTracker; @@ -1934,7 +1954,11 @@ var Keyboard = GObject.registerClass({ finalY += frameRect.y - bufferRect.y; frameRect.y = finalY; + + this._focusTracker.disconnect(this._windowMovedId); window.move_frame(true, frameRect.x, frameRect.y); + this._windowMovedId = this._focusTracker.connect('window-moved', + this._onFocusWindowMoving.bind(this)); } _animateWindow(window, show) { @@ -1957,6 +1981,18 @@ var Keyboard = GObject.registerClass({ }); } + _onFocusWindowMoving() { + if (this._focusTracker.currentWindow === this._focusWindow) { + // Don't use _setFocusWindow() here because that would move the + // window while the user has grabbed it. Instead we simply "let go" + // of the window. + this._focusWindow = null; + this._focusWindowStartY = null; + } + + this.close(true); + } + _setFocusWindow(window) { if (this._focusWindow === window) return;